import { BasicFetchInfoResult, BasicFetchResult, UserFetchResult } from '../model/baseModel';
import { AccountItem, AccountListQueryParams } from './model/accountModel';
import { defHttp } from '/@/utils/http/axios';

import { ErrorMessageMode } from '/@/utils/http/axios/types';

enum Api {
  List = '/system/user/findPageSysUser',
  Role = '/system/role/all',
  Delete = '/system/user/deleteSysUser',
  Add = '/system/user',
  resetPassword = '/system/user/profile/resetPwd',
  Area = '/cityManager/findNoPage',
}

/**
 * @description: 用户列表查询
 */
export function listApi(params: AccountListQueryParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<BasicFetchResult<AccountItem>>(
    {
      url: Api.List,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 角色
 */
export function GetRoleApi(userId?: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<BasicFetchResult<AccountItem>>(
    {
      url: Api.Role,
    },
    {
      errorMessageMode: mode,
    }
  );
}
/**
 * @description: 区域
 */
export function GetAreaApi(userId?: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicFetchResult<AccountItem>>(
    {
      url: Api.Area,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 新增用户
 */
export function AddApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.post(
    {
      url: Api.Add,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 编辑用户
 */
export function EditApi(params, mode: ErrorMessageMode = 'modal') {
  return defHttp.put(
    {
      url: Api.Add,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 删除用户
 */
export function DeleteApi(userId: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.delete(
    {
      url: Api.Delete + `/${userId}`,
    },
    {
      errorMessageMode: mode,
    }
  );
}

/**
 * @description: 删除用户
 */
export function ResetPassword(userId: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.get(
    {
      url: Api.resetPassword + `/${userId}`,
    },
    {
      errorMessageMode: mode,
    }
  );
}
